/*
vTaskList()函数：
使能: configUSE_TRACE_FACILITY
*/

#include "stdio.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "esp_log.h"

static void error_check(void *arg);

static void error_check(void *arg)
{
    while (1)
    {
        ESP_LOGI("ERROR CHECK", "System Info Trace");
        printf("\tDescription\tInternal\tSPIRAM\n");
        printf("Current Free Memory\t%d\t\t%d\n",
               heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL),
               heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
        printf("Largest Free Block\t%d\t\t%d\n",
               heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL),
               heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM));
        printf("Min. Ever Free Size\t%d\t\t%d\n",
               heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL),
               heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
        // char* prtTaskList[512] = "";      
        // vTaskList(prtTaskList);
        // printf("Task            State   Prio    Stack   Num\n");
        // printf(prtTaskList);
        vTaskDelay(30000 / portTICK_PERIOD_MS);
    }
}

void error_check_start(void)
{
    xTaskCreate(error_check, "error_check", 1024 * 3, NULL, 1, NULL);
}
